package ynu.edu.api.client;

import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import ynu.edu.api.dto.PayOrderDTO;
import ynu.edu.api.client.fallback.PayClientFallback;

@FeignClient(value = "pay-service", fallbackFactory = PayClientFallback.class)
public interface PayClient {
    /**
     * 根据交易订单id查询支付单（内部接口）
     * @param id 业务订单id
     * @return 支付单信息
     */
    @GetMapping("/pay-orders/internal/biz/{id}")
    @CircuitBreaker(name = "payService", fallbackMethod = "queryPayOrderFallback")
    PayOrderDTO queryPayOrderByBizOrderNo(@PathVariable("id") Long id);

    /**
     * 熔断降级方法
     * @param id 业务订单id
     * @param ex 异常信息
     * @return 降级后的支付单信息
     */
    default PayOrderDTO queryPayOrderFallback(Long id, Exception ex) {
        return null;
    }
}